home *** CD-ROM | disk | FTP | other *** search
- Path: newshost.cyberramp.net!news
- From: sinan@cyberramp.net (John Noland)
- Newsgroups: comp.lang.c
- Subject: Re: Do you see what is wrong?
- Date: 14 Mar 1996 00:16:30 GMT
- Organization: Prose Software
- Message-ID: <4i7ogu$ij@newshost.cyberramp.net>
- References: <4i72h6$2d4@blaze.cs.jhu.edu>
- NNTP-Posting-Host: ramp2-1.cyberramp.net
- X-Newsreader: WinVN 0.99.5
-
- In article <4i72h6$2d4@blaze.cs.jhu.edu>, lasher@hops.cs.jhu.edu says...
-
- >int j = -1, n, i, distance, nextCoord, current = 0, status[SIZE];
- ^^^^^^
- This is going to be the value of j on the first iteration
- of your for loop below.
- >for( n = 0; n < SIZE; n++, j++ ) {
-
- Initialize j to zero, either here or above in your declaration.
- for (n = 0, j = 0; n < SIZE; n++. j++) {
- The way it is now you're going to try and access the -1 element of
- your array. This isn't a good thing to do!!
- I also don't see why you're using n AND j, superficially it looks like
- they should be the same values. Are you trying to have n access one element
- ahead of j? If you are, you need to make an explicit check below, so that
- you don't try and access an invalid array element (Namely the dreaded -1).
-
- > if( scanf("%f%f", &xtemp, &ytemp) != EOF)
- > {
- > Xposition[n] = xtemp;
- > Yposition[n] = ytemp;
- > }
- > else {
- > printf("Done entering Numbers");
- > n = SIZE;
- > printf("\n%f %f", Xposition[j], Yposition[j]);
- > } /* <== I get a core dump right here. _after_ executing the
- >stuff in the else statemnet */
- > }
- >}
-
-